package com.laf.manage.controller.user;

import com.laf.common.core.controller.BaseController;
import com.laf.common.core.domain.R;
import com.laf.manage.domain.dto.CommentsDTO;
import com.laf.manage.domain.dto.PageDTO;
import com.laf.manage.domain.po.Comments;
import com.laf.manage.domain.query.CommentsQuery;
import com.laf.manage.domain.vo.CommentsVO;
import com.laf.manage.enums.VerifyStatusEnum;
import com.laf.manage.service.ICommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;

/**
 * 评论管理Controller
 *
 * @author zian
 * @date 2024-11-09
 */
@Slf4j
@Api(tags = "评论管理管理")
@RestController("userCommentsController")
@RequestMapping("/user/comments")
@RequiredArgsConstructor
public class CommentsController extends BaseController {

    private final ICommentsService commentsService;


    // 1. 查询动态的评论列表  2. 删除动态  3.新增评论

    /**
     * 查询评论管理列表
     */
    @ApiOperation("查询评论管理列表")
    @GetMapping("/dynamic/list")
    public R<PageDTO<CommentsVO>> list(@Validated CommentsQuery query) {
        Comments comments = new Comments();
        comments.setDynamicId(query.getDynamicId());
        comments.setVerifyStatus(VerifyStatusEnum.VERIFY_PASS.getCode());
        return R.ok(commentsService.getCommentsVOList(comments, query.getPageNo(), query.getPageSize()));
    }


    /**
     * 新增评论管理
     */

    @PostMapping
    @ApiOperation("新增评论管理")
    public R addComments(@RequestBody CommentsDTO dto) {
        commentsService.addComments(dto);
        return R.ok();
    }

    /**
     * 删除评论管理
     */
    @ApiOperation("删除评论管理")
    @DeleteMapping("/{id}")
    public R delByIds(@PathVariable Long id) {
        log.info("删除评论：{}", id);
        commentsService.delByIds(Collections.singletonList(id));
        return R.ok();
    }
}
